<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of agricultural_activities_controller
 *
 * @author root
 */
class AgriculturalActivitiesController extends AppController {

    //put your code here
    var $name = "AgriculturalActivities";

    function index($poll_id) {
        $this->set('usuario', $this->Auth->user());
        $this->AgriculturalActivity->recursive = -1;
        $this->set('activities', $this->AgriculturalActivity->find('all', array('conditions' => array('AgriculturalActivity.poll_id' => $poll_id))));
        $this->data['AgriculturalActivity']['poll_id'] = $poll_id;

        //verifico si esta encuesta ya fue bloqueada, si es asi no se podran
        //imprimir los links para adicionar o modificar actividades agricolas.
        App::Import('model', 'Poll');
        $p = new Poll();
        $p->recursive = -1;

        $this->set('visto_bueno', $p->find('first', array('conditions' => array('Poll.id' => $poll_id), 'fields' => array('Poll.visto_bueno'))));
    }

    function add($poll_id) {
        if (!empty($this->data)) {

            if ($this->AgriculturalActivity->saveAll($this->data)) {
                $this->Session->setFlash('Registro Guardado con exito');
                $this->redirect(array('controller' => 'AgriculturalActivities', 'action' => 'index', $poll_id));
            }
        } else {
            $this->data['AgriculturalActivity']['poll_id'] = $poll_id;
        }
    }

    function edit($id) {
        if (empty($this->data)) {
            $this->AgriculturalActivity->recursive = -1;
            $this->data = $this->AgriculturalActivity->find('first', array('conditions' => array('AgriculturalActivity.id' => $id)));
        } else {
            if ($this->AgriculturalActivity->save($this->data)) {
                $this->Session->setFlash("Registro Editado con éxito");
                $this->redirect(array('controller' => "AgriculturalActivities", 'action' => 'index', $this->data['AgriculturalActivity']['poll_id']));
            }
        }
    }

    function delete($id, $poll) {
        if ($this->AgriculturalActivity->delete($id)) {
            $this->Session->setFlash("Registro borrado con éxito");
            $this->redirect(array('controller' => "AgriculturalActivities", 'action' => 'index', $poll));
        }
    }

}

?>
